﻿using EmoneyWeiXinCommon;
using EmoneyWeiXinEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EmoneyWeiXinDAL
{
    public class Vm_Dms_GetnewsbycodeDAL
    {
        /// <summary>
        /// 获取今日利好提示
        /// </summary>
        /// <returns></returns>
        public List<Vm_Dms_GetnewsbycodeEntity> GetPoint_LH()
        {
            string str = "";
            if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                str = "and DATEDIFF(DAY,GETDATE(),f035d_12001) =-2";
            }
            else if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
            {
                str = "and DATEDIFF(DAY,GETDATE(),f035d_12001) =-1";
            }
            else
            {
                str = "and f035d_12001>=CONVERT(VARCHAR(10),GETDATE(),120)";
            }
            //            string sql = string.Format(@"select f013v_12001,F006V_12006
            // from embase.embase2.dbo.vm_dms_getnewsbycode a,transfer.dbo.tb_news_12006 b,transfer.dbo.tb_news_12007 c
            //where code in('6010102','6080104','6080102','6070502','6060103','6050203','6070404','6060202','6050102','3010202','3050502','3050602')
            //{0} 
            //and newsid_12001=newsid_12006
            //and newsid_12001 =newsid_12007
            //and f009v_12007 like '利好'
            //and f004v_12001>=4 order by f035d_12001 desc", str);
            //利好：
            string sql = string.Format(@"SELECT  f013v_12001 ,F006V_12006
          FROM    ( SELECT    newsid_12001 ,
                    f004v_12001 ,
                    f013v_12001 ,
                    f035d_12001 ,
                    code
          FROM      EMoney_News.dbo.Emoney_News
          WHERE    1=1  {0}
                    AND f004v_12001 >= 4
                    AND ( code = '6010102'
                          OR code = '6080104'
                          OR code = '6080102'
                          OR code = '6070502'
                          OR code = '6060103'
                          OR code = '6050203'
                          OR code = '6070404'
                          OR code = '6060202'
                          OR code = '6050102'
                          OR code = '3010202'
                          OR code = '3050502'
                          OR code = '3050602'
                        )
        ) a ,
        transfer.dbo.tb_news_12006 b ( NOLOCK ) ,
        ( SELECT    newsid_12007
          FROM      transfer.dbo.tb_news_12007 (NOLOCK)
          WHERE     f009v_12007 = '利好'
                    OR f009v_12007 = '重大利好'
        ) c
WHERE   newsid_12001 = newsid_12006
        AND newsid_12001 = newsid_12007
ORDER BY f035d_12001 DESC", str);
            return SQLHelper.GetDataByColumnsLst<Vm_Dms_GetnewsbycodeEntity>(Config.Default, sql, null);
        }


        /// <summary>
        /// 获取走势
        /// </summary>
        /// <returns></returns>
        public Vm_Dms_GetnewsbycodeEntity GetZouShi()
        {
            string sql = "";
            DateTime dt1 = Convert.ToDateTime("15:00:00");
            if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
            {
                if (DateTime.Now > dt1)
                {
                    sql = "select  top 1 f006v_12001,f007v_12001,F013V_12001 ,F035D_12001 from vm_dms_getnewsbycode where code in('3070102','3070204') AND DATEDIFF(DAY,GETDATE(),f035d_12001) =0 order by F035D_12001 desc";
                }
                else
                {
                    sql = "select  top 1 f006v_12001,f007v_12001,F013V_12001 ,F035D_12001 from vm_dms_getnewsbycode where code in('3070102','3070204') AND DATEDIFF(DAY,GETDATE(),f035d_12001) =-3 order by F035D_12001 desc";
                }
            }
            else if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                sql = "select  top 1 f006v_12001,f007v_12001,F013V_12001 ,F035D_12001 from vm_dms_getnewsbycode where code in('3070102','3070204') AND DATEDIFF(DAY,GETDATE(),f035d_12001) =-2 order by F035D_12001 desc";
            }
            else if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
            {
                sql = "select  top 1 f006v_12001,f007v_12001,F013V_12001 ,F035D_12001 from vm_dms_getnewsbycode where code in('3070102','3070204') AND DATEDIFF(DAY,GETDATE(),f035d_12001) =-1 order by F035D_12001 desc";
            }
            else
            {
                if (DateTime.Now > dt1)
                {
                    sql = "select  top 1 f006v_12001,f007v_12001,F013V_12001 ,F035D_12001 from vm_dms_getnewsbycode where code in('3070102','3070204') AND DATEDIFF(DAY,GETDATE(),f035d_12001) =0 order by F035D_12001 desc";
                }
                else
                {
                    sql = "select  top 1 f006v_12001,f007v_12001,F013V_12001 ,F035D_12001 from vm_dms_getnewsbycode where code in('3070102','3070204') AND DATEDIFF(DAY,GETDATE(),f035d_12001) =-1 order by F035D_12001 desc";
                }
            }
            return SQLHelper.GetDataByColumns<Vm_Dms_GetnewsbycodeEntity>(Config.Default, sql, null);
        }
    }
}
